package cn.classTest.mall.service.impl;

import cn.classTest.mall.domain.Department;
import cn.classTest.mall.mapper.DepartmentMapper;
import cn.classTest.mall.query.QueryObject;
import cn.classTest.mall.service.DepartmentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class DepartmentServiceImpl implements DepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;
    @Override
    public void saveOrUpdate(Department department) {
        if (department.getId() == null){
            departmentMapper.save(department);
        }else {
            departmentMapper.update(department);
        }
    }

    @Override
    public PageInfo<Department> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());

        List<Department> departments = departmentMapper.selectAll();

        PageInfo<Department> pageInfo = new PageInfo<>(departments);

        return pageInfo;
    }
}
